#include "zos.h"
#include "shell.h"

typedef struct{
    uint32_t flash_total;
    uint32_t flash_used;
	uint32_t ram_total;
    uint32_t text;
    uint32_t data;
	uint32_t bss;
}mem_state_t;

zos_uint8_t InfoBuffer[512] = {0};

void zos_shell_reboot(int argc, char *agrv[])
{
    zos_reboot();
}

SHELL_EXPORT_CMD(reboot,zos_shell_reboot,ZeusOS reboot);


void zos_shell_show_task_state(int argc, char *agrv[])
{
	vTaskList((char *) &InfoBuffer);
	zos_printf("task           state  priority  stack   num\r\n");
    shell_uart_write(InfoBuffer,strlen(InfoBuffer));
    zos_printf("\r\nX: running   B: blocked   R: ready   D: deleted   S: suspended\r\n");
}
SHELL_EXPORT_CMD(list_task,zos_shell_show_task_state,ZeusOS show task state);

void zos_show_free_mem(int argc, char *agrv[])
{
    mem_state_t memStatus[] = {0};

    zos_enter_critical();
	GetMemStatistics(memStatus);
	zos_exit_critical();

    zos_printf("total flash:%ld\r\n",memStatus->flash_total);
    zos_printf("used flash:%ld\r\n",memStatus->flash_used);
    zos_printf("unused flash:%ld\r\n",memStatus->flash_total - memStatus->flash_used - memStatus->data - memStatus->text);
    zos_printf("total memory:%ld\r\n",memStatus->ram_total);
    zos_printf("used memory:%ld\r\n",memStatus->data + memStatus->text + memStatus->bss);
    zos_printf("unused memory:%ld\r\n",memStatus->ram_total - memStatus->data - memStatus->text -memStatus->bss);
}
SHELL_EXPORT_CMD(free,zos_show_free_mem,ZeusOS show free mem);


void zos_shell_work_unlock(int argc, char *agrv[])
{
    nb_work_unlock();
    zos_task_delay(1000);
}
SHELL_EXPORT_CMD(enter_sleep,zos_shell_work_unlock,ZeusOS enter sleep);


void zos_shell_work_lock(int argc, char *agrv[])
{
    nb_work_lock();
    zos_task_delay(1000);
}
SHELL_EXPORT_CMD(exit_sleep,zos_shell_work_lock,ZeusOS exit sleep);


void zos_shell_standby_unlock(int argc, char *agrv[])
{
    nb_standby_unlock();
    zos_task_delay(1000);
}
SHELL_EXPORT_CMD(enter_standby,zos_shell_standby_unlock,ZeusOS enter standby);

void zos_shell_standby_lock(int argc, char *agrv[])
{
    nb_standby_lock();
    zos_task_delay(1000);
}
SHELL_EXPORT_CMD(exit_standby,zos_shell_standby_lock,ZeusOS exit standby);







